function SortedList( /* object? */ dictionary)
{
	//	summary
	//	creates a collection that acts like a dictionary but is also internally sorted.
	//	Note that the act of adding any elements forces an internal resort, making this object potentially slow.
	this.items = {};

	this._list = [];
	this.size = this._list.length;
}
var $p = Type.extend(SortedList, Cloneable).prototype;

$p.add = function( /* string */k, /* object */ v)
{
	//	summary
	//	add the passed value to the dictionary at location k
	if (!this.items[k])
	{
		this.items[k] = new Entry(k, v);
		this.size = this._list.push(this.items[k]);
		this._list.sort(sorter);
	}
};
$p.clear = function()
{
	//	summary
	//	clear the internal collections
	this.items = {};

	this._list = [];
	this.size = 0;
};
$p.clone = function()
{
	var stl = new SortedList;
	stl.items = this.itmes;
	stl._list = [];
	stl.size = this.size;
	return stl;
//	summary
//	create a clone of this sorted list
//	dojox.collections.SortedList
};
$p.containsKey = function( /* string */k)
{
	//	summary
	//	Check to see if the list has a location k
	return (this.items[k] != null); //	bool
};
$p.containsValue = function( /* object */o)
{
	//	summary
	//	Check to see if this list contains the passed object
	for(var n in this.items)
	{
		if(this.items[n].value == o)
			return true;
	}
	return false;//	bool
};
$p.entry = function( /* string */k)
{
	//	summary
	//	return the object at location k
	return this.items[k]; //	dojox.collections.DictionaryEntry
};
$p.getAt = function( /* int */i)
{
	//	summary
	//	return the item at index i
	return this._list[i].valueOf(); //	object
};

$p.getKey = function( /* int */i)
{
	//	summary
	//	return the key of the item at index i
	return this._list[i].key;
};
$p.keys = function()
{
	//	summary
	//	return an array of the keys set in this list

	var arr = [];
	for(var n in this.items)
	{
		arr.push(this.items[n].key);
	}
	return new Iterator(arr);//	array
};
$p.values = function()
{
	//	summary
	//	return an array of values in this list
	var arr = [];
	for(var n in this.items)
	{
		arr.push(this.items[n].value);
	}
	return new Iterator(arr);//	array
};
$p.indexOfKey = function( /* string */k)
{
	//	summary
	//	return the index of the passed key.
	for (var i = 0; i < this._list.length; i++)
	{
		if (this._list[i].key == k)
		{
			return i; //	int
		}
	}
	return -1; //	int
};
$p.indexOfValue = function( /* object */o)
{
	//	summary
	//	return the first index of object o
	for (var i = 0; i < this._list.length; i++)
	{
		if (this._list[i].value == o)
		{
			return i; //	int
		}
	}
	return -1; //	int
};
$p.item = function( /* string */k)
{
	// 	summary
	//	return the value of the object at location k.
	if (k in this.items)
	{
		return this.items[k].valueOf(); //	object
	}
	return undefined;                   //	object
};
$p.remove = function( /* string */k)
{
	// 	summary
	//	remove the item at location k and rebuild the internal collections.
	delete this.items[k];
	this._list = [];

	for (var o in this.items)
	{
		this._list.push(this.items[o]);
	}
	this._list.sort(sorter);
	this.size--;
};
$p.removeAt = function( /* int */i)
{
	//	summary
	//	remove the item at index i, and rebuild the internal collections.
	delete this.items[this._list[i].key];
	this._list = [];

	for (var o in this.items)
	{
		this._list.push(this.items[o]);
	}
	this._list.sort(sorter);
	this.size--;
};
$p.replace = function( /* string */k, /* object */ v)
{
	//	summary
	//	Replace an existing item if it's there, and add a new one if not.
	if (!this.items[k])
	{
		//	we're adding a new object, return false
		this.add(k, v);
		return false; // bool
	}
	else
	{
		//	we're replacing an object, return true
		this.items[k] = new Entry(k, v);
		this._list = [];

		for (var o in this.items)
		{
			this._list.push(this.items[o]);
		}
		this._list.sort(sorter);
		return true; // bool
	}
};
$p.setAt = function( /* int */i, /* object */ o)
{
	//	summary
	//	set an item by index
	this.items[this._list[i].key].value = o;
	this._list = [];

	for (var o in this.items)
	{
		this._list.push(this.items[o]);
	}
	this._list.sort(sorter);
};

$p.toArray = function()
{
	var entities = [], i = 0, h;
	for(h in this._table)
	{
		entities[i++] = this.items[h];
	}
	return entities;
}

$p = null;

function sorter(a, b)
{
	if (a.key > b.key)
		return 1;

	if (a.key < b.key)
		return -1;

	return 0;
};